""" Input mode to plot a course """
from pgEngine.point import Point
from pygame.locals import *

class DragMapMode:
    def __init__(self, window):
        self.window = window
        self.map = window.map
        
        # Set the source
        self.sourcePos = Point(self.window.mouseX,
                               self.window.mouseY,
                               float)
    
    def onEvent(self, event):
        if event.type == MOUSEBUTTONUP:
            # Plot the course.
            self.window.mode.pop()
            return False
    
        return None
    
    def onDrawMapObjects(self, surface):
        sourcePos = self.sourcePos
        targetPos = Point(self.window.mouseX,
                          self.window.mouseY,
                          float)
        delta = (targetPos - sourcePos) / Point(250.0, -250.0)
        self.window.mappos -= delta
